/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package communication.impl;

import communication.CommunicationPackage;
import communication.Controller;
import communication.RestFulService;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Controller</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link communication.impl.ControllerImpl#getUrlMapping <em>Url Mapping</em>}</li>
 *   <li>{@link communication.impl.ControllerImpl#getContainsServices <em>Contains Services</em>}</li>
 *   <li>{@link communication.impl.ControllerImpl#getName <em>Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ControllerImpl extends EObjectImpl implements Controller {
	/**
	 * The default value of the '{@link #getUrlMapping() <em>Url Mapping</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUrlMapping()
	 * @generated
	 * @ordered
	 */
	protected static final String URL_MAPPING_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getUrlMapping() <em>Url Mapping</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUrlMapping()
	 * @generated
	 * @ordered
	 */
	protected String urlMapping = URL_MAPPING_EDEFAULT;

	/**
	 * The cached value of the '{@link #getContainsServices() <em>Contains Services</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContainsServices()
	 * @generated
	 * @ordered
	 */
	protected EList<RestFulService> containsServices;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ControllerImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CommunicationPackage.Literals.CONTROLLER;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getUrlMapping() {
		return urlMapping;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUrlMapping(String newUrlMapping) {
		String oldUrlMapping = urlMapping;
		urlMapping = newUrlMapping;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CommunicationPackage.CONTROLLER__URL_MAPPING, oldUrlMapping, urlMapping));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<RestFulService> getContainsServices() {
		if (containsServices == null) {
			containsServices = new EObjectContainmentEList<RestFulService>(RestFulService.class, this, CommunicationPackage.CONTROLLER__CONTAINS_SERVICES);
		}
		return containsServices;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CommunicationPackage.CONTROLLER__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CommunicationPackage.CONTROLLER__CONTAINS_SERVICES:
				return ((InternalEList<?>)getContainsServices()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CommunicationPackage.CONTROLLER__URL_MAPPING:
				return getUrlMapping();
			case CommunicationPackage.CONTROLLER__CONTAINS_SERVICES:
				return getContainsServices();
			case CommunicationPackage.CONTROLLER__NAME:
				return getName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CommunicationPackage.CONTROLLER__URL_MAPPING:
				setUrlMapping((String)newValue);
				return;
			case CommunicationPackage.CONTROLLER__CONTAINS_SERVICES:
				getContainsServices().clear();
				getContainsServices().addAll((Collection<? extends RestFulService>)newValue);
				return;
			case CommunicationPackage.CONTROLLER__NAME:
				setName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CommunicationPackage.CONTROLLER__URL_MAPPING:
				setUrlMapping(URL_MAPPING_EDEFAULT);
				return;
			case CommunicationPackage.CONTROLLER__CONTAINS_SERVICES:
				getContainsServices().clear();
				return;
			case CommunicationPackage.CONTROLLER__NAME:
				setName(NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CommunicationPackage.CONTROLLER__URL_MAPPING:
				return URL_MAPPING_EDEFAULT == null ? urlMapping != null : !URL_MAPPING_EDEFAULT.equals(urlMapping);
			case CommunicationPackage.CONTROLLER__CONTAINS_SERVICES:
				return containsServices != null && !containsServices.isEmpty();
			case CommunicationPackage.CONTROLLER__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (urlMapping: ");
		result.append(urlMapping);
		result.append(", name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //ControllerImpl
